-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass explicit false
value for falsey checkboxes
#413
base: master
Are you sure you want to change the base?
Conversation
Hmm. This seems like one of those things it would be really helpful to have a test case for. How should I review? Do we need to accommodate |
@danielbachhuber No, I don't think we need to accommodate the radio button. What we've changed here is how a truthy default works with the checkbox. Before this fix, assuming If the default of a radio is some 'value', then we expect the shortcode to look like I've added a test based on @niallkennedy's use case. |
|
||
// Test with falsey checkbox | ||
_shortcode.get( 'attrs' ).last().set( 'value', 'false' ); | ||
expect( _shortcode.formatShortcode() ).toEqual( '[test_shortcode checkbox="false"]' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect this to be checkbox=""
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielbachhuber That would evaluate as null, which would trigger the default to override (Which is the behavior we are trying to prevent).
@davisshaver I think we should chat about this some during the Shortcake chat today. I'm not 100% sure this is the behavior we want. |
@danielbachhuber Sure, fine with me. Maybe we could ask @niallkennedy what he expects, too. |
I look for falsey values (0, 'false', etc) for a shortcode override. I ignore empty string values for a boolean attribute. The checked behavior passes a 'true' string to be interpreted by the shortcode handler. If you support Shortcake you also need to accept a value of 'true' for a boolean shortcode attribute. A string of 'false' represents the opposite state in my mind, and provides consistency between the required shortcode attribute values a shortcode handler should accept to be compatible with Shortcake. |
Thanks @niallkennedy! |
@danielbachhuber based on #413 (comment), what do you think about merging? Should we get a second opinion from @mattheu or @goldenapples? |
@danielbachhuber Assigning this to you for a second opinion – still hesitant about behavior change? |
Yes. For now, let's just bump it from the v0.5.0 milestone. |
It would be great to see this merged at some point. And if not, at least an explanation of why this might be unwanted behavior and possible workarounds? Currently I'm just avoiding checkbox fields because of this and using select fields instead. |
I like this concept, but it seems that we would need some way of enabling this as an opt-in feature on an attribute. I know that a number of shortcodes I've built would break if this were merged as-is, as there are plenty of places where I just check for a boolean attribute to be present in the callback, and It might be good to follow the pattern we established with the "encoded" parameter, where a flag set on an attribute could be used in a filter on "shortcode_atts_{$shortcode_tag}" like this one is to parse boolean attributes and either unset the attribute or set it to a boolean false rather than a string. |
Checkbox values will be passed to the shortcode for both
true
andfalse
states.See #359